package com.zengdada.authority.utils.excel.export.style;

import com.zengdada.authority.utils.CommonUtils;
import org.apache.poi.ss.usermodel.Font;

import java.util.Objects;

/**
 * @author 12614
 * @contact 1261438511@qq.com
 * @date 2020-06-07 20:55
 * @describe TODO
 */
public class MyFont {
    private String fontName;
    private Short fontHeight;
    private Short fontHeightInPoints;
    private Boolean italic;
    private Boolean strikeout;
    private Short color;
    private Short typeOffset;
    private Byte underline;
    private Byte charSet;
    //    private int CharSet;
    private Boolean bold;

    public MyFont() {
    }

    public MyFont(MyFont font) {
        this.merge(font);
    }

    public MyFont(Font font) {
        CommonUtils.copyObjectNotNullAttributeByGetMethod(font, this, true);
    }

    public Font initFont(Font font) {
        CommonUtils.copyObjectNotNullAttribute(this, font, true);
        return font;
    }

    public MyFont merge(MyFont font) {
        CommonUtils.copyObjectNotNullAttribute(font, this, true);
        return this;
    }


    public String getFontName() {
        return fontName;
    }

    public MyFont setFontName(String fontName) {
        this.fontName = fontName;
        return this;
    }

    public Short getFontHeight() {
        return fontHeight;
    }

    public MyFont setFontHeight(Short fontHeight) {
        this.fontHeight = fontHeight;
        return this;
    }

    public Short getFontHeightInPoints() {
        return fontHeightInPoints;
    }

    public MyFont setFontHeightInPoints(Short fontHeightInPoints) {
        this.fontHeightInPoints = fontHeightInPoints;
        return this;
    }

    public Boolean getItalic() {
        return italic;
    }

    public MyFont setItalic(Boolean italic) {
        this.italic = italic;
        return this;
    }

    public Boolean getStrikeout() {
        return strikeout;
    }

    public MyFont setStrikeout(Boolean strikeout) {
        this.strikeout = strikeout;
        return this;
    }

    public Short getColor() {
        return color;
    }

    public MyFont setColor(Short color) {
        this.color = color;
        return this;
    }

    public Short getTypeOffset() {
        return typeOffset;
    }

    public MyFont setTypeOffset(Short typeOffset) {
        this.typeOffset = typeOffset;
        return this;
    }

    public Byte getUnderline() {
        return underline;
    }

    public MyFont setUnderline(Byte underline) {
        this.underline = underline;
        return this;
    }

    public Byte getCharSet() {
        return charSet;
    }

    public MyFont setCharSet(Byte charSet) {
        this.charSet = charSet;
        return this;
    }

    public Boolean getBold() {
        return bold;
    }

    public MyFont setBold(Boolean bold) {
        this.bold = bold;
        return this;
    }

    public MyFont setCharSet(int charset) {
        byte cs = (byte) charset;
        if (charset > 127) {
            cs = (byte) (charset - 256);
        }
        setCharSet(cs);
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MyFont myFont = (MyFont) o;
        return Objects.equals(fontName, myFont.fontName) &&
                Objects.equals(fontHeight, myFont.fontHeight) &&
                Objects.equals(fontHeightInPoints, myFont.fontHeightInPoints) &&
                Objects.equals(italic, myFont.italic) &&
                Objects.equals(strikeout, myFont.strikeout) &&
                Objects.equals(color, myFont.color) &&
                Objects.equals(typeOffset, myFont.typeOffset) &&
                Objects.equals(underline, myFont.underline) &&
                Objects.equals(charSet, myFont.charSet) &&
                Objects.equals(bold, myFont.bold);
    }

    @Override
    public int hashCode() {
        return Objects.hash(fontName, fontHeight, fontHeightInPoints, italic, strikeout, color, typeOffset, underline, charSet, bold);
    }
}
